/*
 * Copyright (c) 2012-2014, EpicSaaS Yuan Xin technology Co., Ltd.
 * 
 * All rights reserved.
 */
package com.epicsaas.app.ksdapp.android.bean;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 服务方法返回的类型.
 *
 * <ul>
 * <li>所有的AJAX响应，以JSON格式返回到前台时，也都是通过此类来包装</li>
 * <li>所有服务方法的返回类型必须是此类</li>
 * </ul>
 *
 * 默认构造该类对象时 {@link #succeed} 为 {@code true}。
 *
 * @param <T> 返回的数据类型
 * @author doveYH
 * @author Yuanjun.Li
 * @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
 * @version 2.0.0.0, Jan 28, 2013
 */
public final class ServiceResult<T> implements Serializable {

    /**
     * serialVersionUID.
     */
    private static final long serialVersionUID = 6977558218691386450L;

    /**
     * 成功与否
     */
    private boolean succeed = true;

    /**
     * 代码
     */
    private int code = -1;

    /**
     * 提示信息
     */
    private String msg;

    /**
     * 数据对象
     */
    private T data;

    public ServiceResult() {
    }

    public ServiceResult(T data) {
        this.data = data;
    }

    public ServiceResult(boolean succeed, int code, String msg) {
        this.succeed = succeed;
        this.code = code;
        this.msg = msg;
    }

    public ServiceResult(boolean succeed, T data, String msg) {
        this.succeed = succeed;
        this.data = data;
        this.msg = msg;
    }

    public ServiceResult(boolean succeed, T data, int code, String msg) {
        this.succeed = succeed;
        this.data = data;
        this.code = code;
        this.msg = msg;
    }

    public ServiceResult(boolean succeed, String msg) {
        this.succeed = succeed;
        this.msg = msg;
    }

    public boolean isSucceed() {
        return succeed;
    }

    public void setSucceed(boolean succeed) {
        this.succeed = succeed;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    /**
     * 所有额外的列属性
     */
    private Map<String, Object> additionalProperties = new HashMap<String, Object>();

    public Map<String, Object> getAdditionalProperties() {
        return this.additionalProperties;
    }

    public void setAdditionalProperties(String name, Object value) {
        this.additionalProperties.put(name, value);
    }

    public Object getAdditionalProperties(String name) {
        return this.additionalProperties.get(name);
    }
}
